home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap05 / ColorTester.java < prev    next >
Text File  |  1996-10-08  |  2KB  |  56 lines

  1. // ColorTester.java
  2. import vrml.*;
  3. import vrml.node.*;
  4. import vrml.field.*;
  5.  
  6. public class ColorTester extends Script{
  7.    ColorPanel panel;
  8.     
  9.    SFFloat a_field, s_field, t_field;
  10.    SFColor dc_field, ec_field, sc_field;
  11.  
  12.    public void initialize(){
  13.       // get the reference to the target node.
  14.       Node target = (Node)((SFNode)getField("target")).getValue();
  15.       
  16.       panel = new ColorPanel(this);         // start the panel.
  17.         
  18.       // get the references to exposed fields, event-in/outs.
  19.       a_field = (SFFloat)target.getExposedField("ambientIntensity");    
  20.       dc_field = (SFColor)target.getExposedField("diffuseColor");
  21.       ec_field = (SFColor)target.getExposedField("emissiveColor");
  22.       s_field = (SFFloat)target.getExposedField("shininess");
  23.       sc_field = (SFColor)target.getExposedField("specularColor");
  24.       t_field = (SFFloat)target.getExposedField("transparency");
  25.     }
  26.  
  27.     public void processEvent(Event ev){
  28.       if(ev.getName().equals("entered")){
  29.          ConstSFBool v = (ConstSFBool)ev.getValue();
  30.  
  31.          if(v.getValue()){ panel.map(); }
  32.          else { panel.hide(); }
  33.       }
  34.     }
  35.  
  36.     public void shutdown(){ panel.dispose(); }   
  37.  
  38.     public float get_ambientIntensity(){ return(a_field.getValue()); }
  39.     public void set_ambientIntensity(float val){ a_field.setValue(val); }
  40.  
  41.     public void get_diffuseColor(float[] rgb){ dc_field.getValue(rgb); }
  42.     public void set_diffuseColor(float[] val){ dc_field.setValue(val); }
  43.  
  44.     public void get_emissiveColor(float[] rgb){ ec_field.getValue(rgb); }
  45.     public void set_emissiveColor(float[] val){ ec_field.setValue(val); }
  46.  
  47.     public float get_shininess(){ return(s_field.getValue()); }
  48.     public void set_shininess(float val){ s_field.setValue(val); }
  49.  
  50.     public void get_specularColor(float[] rgb){ sc_field.getValue(rgb); }
  51.     public void set_specularColor(float[] val){ sc_field.setValue(val); }
  52.  
  53.     public float get_transparency(){ return(t_field.getValue()); }
  54.     public void set_transparency(float val){ t_field.setValue(val); }
  55. }
  56.